package com.awa.usercenter.controller;

import com.awa.usercenter.common.BaseResponse;
import com.awa.usercenter.common.utils.ResultUtils;
import com.awa.usercenter.constant.FeedbackStatus;
import com.awa.usercenter.model.domain.request.FeedbackIdBatchRequest;
import com.awa.usercenter.model.domain.response.PageInfo;
import com.awa.usercenter.model.domain.response.UserNumResponse;
import com.awa.usercenter.model.domain.response.FeedbackResponse;
import com.awa.usercenter.service.FeedbackService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;

@RestController
@RequestMapping("/feedback")
@Tag(name = "用户反馈")
public class FeedbackController {
    @Autowired
    private FeedbackService feedbackService;

    /**
     * 用户数量接口
     * auth 管理员
     * @return
     */
    @GetMapping("/number")
    @Operation(summary = "用户反馈表格数据接口")
    public BaseResponse<UserNumResponse> getUserNum(){
        UserNumResponse userNumResponse = feedbackService.getUserNum();
        return ResultUtils.success(userNumResponse);
    }

    /**
     * 用户反馈表格数据接口
     * @param pageNum
     * @param pageSize
     * auth 管理员
     * @return
     */
    @GetMapping("/table/{pageNum}/{pageSize}/{status}")
    @Operation(summary = "用户反馈表格数据接口")
    public BaseResponse<List<FeedbackResponse>> getUserRecordingListPage(
            @PathVariable("pageNum") Long pageNum,
            @PathVariable("pageSize") Long pageSize,
            @PathVariable("status") Long status){
        PageInfo<FeedbackResponse> userRecordingListPage = feedbackService.getUserRecordingListPage(pageNum, pageSize,status);
        return ResultUtils.success(userRecordingListPage);
    }

    /**
     * 用户反馈批量审批
     */
    @PostMapping("/accept")
    @Operation(summary = "用户反馈批量审批")
    public BaseResponse<String> batchAccept(@RequestBody FeedbackIdBatchRequest feedbackIdBatchRequest){
        ArrayList<String> feedbackIds = feedbackIdBatchRequest.getFeedbackIds();
        // status 0 未完成 1 已通过 2 已忽略
        // 审批的状态
        Long status = FeedbackStatus.DONE;
        return feedbackService.batchUpateStatus(feedbackIds,status);
    }

    /**
     * 用户反馈批量忽略
     */
    @PostMapping("/ignore")
    @Operation(summary = "用户反馈批量忽略")
    public BaseResponse<String> batchIgnore(@RequestBody FeedbackIdBatchRequest feedbackIdBatchRequest){
        ArrayList<String> feedbackIds = feedbackIdBatchRequest.getFeedbackIds();
        // status 0 未完成 1 已通过 2 已忽略
        Long status = FeedbackStatus.IGNORE;
        return feedbackService.batchUpateStatus(feedbackIds,status);
    }

    /**
     * 用户反馈批量撤回
     */
    @PostMapping("/drawback")
    @Operation(summary = "用户反馈批量撤回")
    public BaseResponse<String> batchDrawback(@RequestBody FeedbackIdBatchRequest feedbackIdBatchRequest){
        ArrayList<String> feedbackIds = feedbackIdBatchRequest.getFeedbackIds();
        // status 0 未完成 1 已通过 2 已忽略
        Long status = FeedbackStatus.DOING;
        return feedbackService.batchUpateStatus(feedbackIds,status);
    }
}
